package com.highspeed.bdk.service.base;

import com.bianmaba.spring.data.jpa.repository.support.ExtendedRepository;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * Created by chenjiabin on 2018/3/23.
 */
public interface IBdkBaseService<T, ID extends Serializable> {
    ExtendedRepository<T, ID> getRepository();


    <S extends T> S save(S entity);

    <S extends T> S saveAndFlush(S entity);

    <S extends T> List<S> save(Iterable<S> entities);

    void delete(ID id);

    void delete(ID[] ids);


    T getOne(ID id);

    T findOne(ID id);

    List<T> all();

    Page<T> query(final Map<String, Object> params, final Pageable pageable);

    List<T> queryToList(final Map<String, Object> params, final Pageable pageable);

    Page<T> queryDistinct(final Map<String, Object> params, final Pageable pageable);

    List<T> queryDistinctToList(Map<String, Object> params, final Pageable pageable);


    boolean exists(ID id);

    <S extends T> boolean exists(Example<S> example);

    long count();

    <S extends T> long count(Example<S> example);

    void flush();

    void clear();
}

